<header>
    <hgroup>
        <h1>Produit { $data->name }</h1>
    </hgroup>
</header>

<ul>
    <li><strong>Date d'enregistrement :</strong> { $data->date_create|date_format:"%d/%m/%Y" }</li>
    <li><strong>Relevé PDF :</strong> <a href="{$BASE_URL}reports/pdf/{$data->_id}-{ $data->name|replace:' ':'-' }">Télécharger</a></li>
</ul>
<br />

<table>
    <thead>
        <tr>
            <th>Date</th>
            <th>Prix</th>
            <th>Marque</th>
            <th>Catégorie</th>
            <th>Magasin</th>
            <th>Chasseur</th>
            <th>Note</th>
        </tr>
    </thead>
    <tbody>
    { foreach from=$releves_reverse item=rel }
        <tr>
            <td>{ $rel.date_create|date_format:"%d/%m/%Y" }</td>
            <td class="releve {if $rel.prix > $medianes}red{else}green{/if}">{ $rel.prix } € / <span title="{ $rel.conditionnement->name }">{ $rel.unite }</span></td>
            <td>{ $rel.marque->name }</td>
            <td><a href="{$BASE_URL}reports/categorie/{$rel.categorie->_id}-{ $rel.categorie->name|replace:' ':'-' }">{$rel.categorie->name}</a></td>
            <td><a href="{$BASE_URL}stores/{ $rel.magasin->_id }-{ $rel.magasin->name|replace:' ':'-' }">{ $rel.magasin->name }</a></td>
            <td><a href="{$BASE_URL}hunters/{ $rel.chasseur->_id }-{ $rel.chasseur->nom|replace:' ':'-' }-{ $rel.chasseur->prenom|replace:' ':'-' }">{ $rel.chasseur->prenom }</a></td>
            <td>
                <div class="jRating" data="{$rel.note}_{$rel._id}"></div>
            </td>
        </tr>
    { /foreach }
    </tbody>
</table>

<div id="contentChart" style="width: 100%; height: 400px; margin: 0 auto"></div>

{literal}
<script>
	var ChartData = {
        chart: {
            renderTo: 'contentChart',
            zoomType: 'xy'
        },
        title: {
            text: '{/literal}{$data->name}{literal}',
            style: {
                color: '#000000'
            }
        },
        subtitle: {
            text: ' Évolution des prix',
            style: {
                color: '#000000'
            }
        },
        xAxis: [{
            categories: [{/literal}
                    { foreach from=$releves item=rel }
                    "{$rel.date_create|date_format:"%d/%m/%Y"}",
                    {/foreach}
                   {literal}
                  ]
        }],
        yAxis: [{ // Primary yAxis
            labels: {
                formatter: function() {
                    return this.value +' €';
                },
                style: {
                    color: '#000000'
                }
            },
            title: {
                text: 'Prix constaté',
                style: {
                    color: '#89A54E'
                }
            }
        }, { // Secondary yAxis
            title: {
                text: 'Prix moyen',
                style: {
                    color: '#4572A7'
                }
            },
            labels: {
                formatter: function() {
                    return this.value +' €';
                },
                style: {
                    color: '#000000'
                }
            },
            opposite: true,
            linkedTo: 0
        }/*, { // median
            title: {
                text: 'Prix médian',
                style: {
                    color: '#FF0000'
                }
            },
            labels: {
                formatter: function() {
                    return this.value +' €';
                },
                style: {
                    color: '#FF0000'
                }
            },
            opposite: true,
            linkedTo: 0
        }*/
        ],
        tooltip: {
            formatter: function() {
                return ''+
                    this.x +': '+ this.y +
                    this.series.name == ' €'
            }
        },
        legend: {
            layout: 'vertical',
            align: 'left',
            x: 120,
            verticalAlign: 'top',
            y: 20,
            floating: true,
            backgroundColor: '#FFFFFF'
        },
        series: [{
            name: 'Prix constaté',
            color: '#4572A7',
            type: 'column',
            yAxis: 1,
            data: [{/literal}
                    { foreach from=$releves item=rel }
                    {$rel.prix},
                    {/foreach}
                   {literal}
                  ]


        }, {
            name: 'Prix moyen',
            color: '#89A54E',
            type: 'spline',
            dashStyle: 'shortdot',
               data: [{/literal}
                       { foreach from=$releves item=rel }
                       {$rel.prix},
                       {/foreach}
                      {literal}
                     ]

        }, {
            name: 'Prix médian',
            color: '#FF0000',
            type: 'spline',
            dashStyle: 'shortdot',
               data: [{/literal}
                       { foreach from=$releves item=rel }
                       {$medianes},
                       {/foreach}
                      {literal}
                     ]

        }]
    };
</script>
{/literal}

<section class="commentaires">
    <header>
        <h1>Commentaires</h1>
    </header>

    <ul>
        { if $coms }
        { foreach from=$coms item=com }
        <li class="commentaire">
            <span class="date">{ $com.date_create|date_format:"%d/%m/%Y" }</span>

            <span class="message">
                <span class="user">{ $com.user->prenom } { $com.user->nom }</span>
                { $com.message }
            </span>
        </li>
        { /foreach }
        { else }
        <li class="commentaire">
            <span class="message">Aucun commentaire pour le moment...</span>
        </li>
        { /if }

        { if $user_connected }
        <li class="commentaire">
            <form method="post" action="{ $HTTP_HOST_REQUEST }">
                <input type="hidden" name="todo" value="Commentaire" />
                <input type="hidden" name="object_id" value="{ $data->_id }" />

                <span class="date">
                    <button type="submit">
                        <img src="{ $BASE_URL }themes/macrise/images/plus.png" width="32" height="32" alt="Ajouter" />
                    </button>
                </span>

                <span class="message">
                    <textarea name="message" placeholder="Votre message"></textarea>
                </span>
            </form>
        </li>
        { /if }
    </ul>
</section>